#include "inifilehelper.h"
#include <QSettings>

QString IniFilehelper::hostName = "";
QString IniFilehelper::User="";
QString IniFilehelper::Pwd="";

QString IniFilehelper::tcpIp = "";
int IniFilehelper::tcpPort= 0;
int IniFilehelper::camNum=0;
int IniFilehelper::ignoreMeter = 0;

bool IniFilehelper::ReadIni(const QString &Path)
{

    QSettings settings(Path,QSettings::IniFormat);
    settings.beginGroup("DataBaseInfo");
    IniFilehelper::hostName =  settings.value("DatabaseIP").toString();
    IniFilehelper::User =  settings.value("user").toString();
    IniFilehelper::Pwd =  settings.value("pwd").toString();
    IniFilehelper::camNum=  settings.value("cameraNumber").toInt();
    settings.endGroup();
    settings.beginGroup("TcpInfo");
    IniFilehelper::tcpIp =  settings.value("tcpIp").toString();
    IniFilehelper::tcpPort =  settings.value("tcpPort").toInt();
    settings.endGroup();
    settings.beginGroup("Defect");
    IniFilehelper::ignoreMeter =  settings.value("ignoreMeter").toInt();
    settings.endGroup();
    qDebug()<<"设置忽略头部米数为"<<IniFilehelper::ignoreMeter <<"mm";
    return true;
}

bool IniFilehelper::WriteIni(const QString &Path)
{
    QSettings settings(Path,QSettings::IniFormat);
    settings.beginGroup("DataBaseInfo");
    settings.setValue("DatabaseIP","127.0.0.1");
    settings.setValue("user","ARNTUSER");
    settings.setValue("pwd","ARNTUSER");
    settings.setValue("table","SteelRecord");
    settings.setValue("cameraNumber","4");
    settings.endGroup();

    settings.beginGroup("TcpInfo");
    settings.setValue("tcpIp"," ");
    settings.setValue("tcpPort","0");
    settings.endGroup();
    settings.beginGroup("Defect");
    settings.setValue("ignoreMeter","0");
    settings.endGroup();

    ReadIni(Path);
    return true;
}
